package com.cltech.entity.sys;

import com.cltech.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2019/3/19.
 */
@Getter
@Setter
@Entity
public class SysOrganization extends BaseEntity {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;
    private String name;
    private String code;
    @JsonIgnore
    private String parentIds;
    @JsonIgnore
    @ManyToOne
    @JoinColumn(name="parent_id")
    private SysOrganization parent;
    @JsonIgnore
    @OneToMany(cascade = {CascadeType.REMOVE}, fetch = FetchType.LAZY, mappedBy = "parent")
    private Set<SysOrganization> children = new HashSet<>();
    /**
     * 拥有的用户
     */
    @JsonIgnore
    @OneToMany(mappedBy="organization",cascade=CascadeType.ALL,fetch=FetchType.LAZY)
    private Set<SysUser> users = new HashSet<>();
}
